"use strict";
cc._RF.push(module, '8e0cctcEbZO37/60kD776BI', 'addUserProp');
// scripts/O1ModuleRes/control/addUserProp.ts

"use strict";
var __extends = (this && this.__extends) || (function () {
    var extendStatics = function (d, b) {
        extendStatics = Object.setPrototypeOf ||
            ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
            function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
        return extendStatics(d, b);
    };
    return function (d, b) {
        extendStatics(d, b);
        function __() { this.constructor = d; }
        d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
    };
})();
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
    var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
    if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
    else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
    return c > 3 && r && Object.defineProperty(target, key, r), r;
};
Object.defineProperty(exports, "__esModule", { value: true });
var gameEngine_1 = require("../../engines/gameEngine");
var userInterface_1 = require("../../engines/services/userContent/userInterface");
var data_control_1 = require("../../engines/libs/data_control");
var gameConfig_1 = require("../../engines/configs/gameConfig");
var videoBtn_1 = require("../../Game/Obj/videoBtn");
var MainRoot_1 = require("../../Game/MainRoot");
var Enum_1 = require("../../Game/Enum");
var _a = cc._decorator, ccclass = _a.ccclass, property = _a.property;
var addUserProp = /** @class */ (function (_super) {
    __extends(addUserProp, _super);
    function addUserProp() {
        var _this = _super !== null && _super.apply(this, arguments) || this;
        _this.detail = null;
        _this.title = null;
        _this.showNum = null;
        _this.spIcon = null;
        _this.spfIcons = [];
        _this.titleImg = null;
        _this.messageImg = null;
        _this.infinityBtn = null;
        _this.lbInfinityNum = null;
        _this.hintNode = null;
        _this.videoBtn = null;
        _this.m_propType = null;
        _this.m_propCount = null;
        _this.infinityStr = [
            "再看两次就好啦",
            "看最后一次，谢谢老板",
        ];
        return _this;
    }
    addUserProp_1 = addUserProp;
    // LIFE-CYCLE CALLBACKS:
    addUserProp.prototype.onLoad = function () {
    };
    addUserProp.prototype.start = function () {
        this.initView();
        this.node.zIndex = cc.macro.MAX_ZINDEX;
    };
    addUserProp.prototype.setData = function (propType, propNumber) {
        this.m_propType = propType;
        this.m_propCount = propNumber;
        // this.m_propType = REWARD_TYPE.propType;
        // this.m_propCount = 1;
        // if(propType == REWARD_TYPE.POWER){
        //     O1HD.getModules().uiControlModule.showInfinityPower(gameConfig.CLICK_POWER_INFINITY_PROBABILITY, mainRoot.UIRoot);
        // }
    };
    addUserProp.prototype.initView = function () {
        // if (this.m_propType == null) {
        //     console.error('#505131 添加用户道具错误');
        //     return;
        // }
        //出场动画
        gameEngine_1.modules().uiControlModule.showHideDialogAnimation(this.detail, true);
        //
        this.showNum.string = "+" + data_control_1.default.getNumberFormat(this.m_propCount);
        this.showNum.node.active = this.m_propType != 0;
        this.videoBtn.enabled = this.m_propType != 0;
        // this.showNum.string = `:${data_control.getNumberFormat(this.m_propCount)}`;
        this.spIcon.spriteFrame = this.spfIcons[this.m_propType];
        this.infinityBtn.active = this.m_propType != 0 && !gameEngine_1.default.getServices().userSrv.getInfinityPower();
        this.UpdateLookLabel();
        this.title.string = ['获取免广告币', '获取体力', '获取钻石'][this.m_propType];
        // let imgUrl = [null,'GetPowerTitle',null][this.m_propType];
        // this.title.node.active = (imgUrl==null);
        // node_component.loadResourcesPicture(`Img/${imgUrl}`,this.titleImg);
    };
    addUserProp.prototype.onBtnClose = function () {
        gameEngine_1.managers().soundMgr.playSound('mainSound/anNiu').then();
        this.onClose();
    };
    addUserProp.prototype.onClose = function () {
        var _this = this;
        gameEngine_1.modules().uiControlModule.showHideDialogAnimation(this.detail, false, function () {
            _this.node.destroy();
        });
    };
    addUserProp.prototype.onBtnGet = function () {
        var _this = this;
        gameEngine_1.managers().soundMgr.playSound('mainSound/anNiu').then();
        var lookString = '未定义获取道具说明';
        var lookOverFunction = null;
        var rewardType = null;
        lookOverFunction = function () {
            gameEngine_1.services().userSrv.addPowerOfVideo();
        };
        rewardType = userInterface_1.REWARD_TYPE.COIN;
        // lookString = '获取体力';
        // let lookString = '未定义获取道具说明';
        // let lookOverFunction: () => void = null;
        // let rewardType: REWARD_TYPE = null;
        switch (this.m_propType) {
            case userInterface_1.REWARD_TYPE.COIN: {
                lookOverFunction = function () {
                    gameEngine_1.services().userSrv.setCoins(_this.m_propCount, true);
                };
                rewardType = userInterface_1.REWARD_TYPE.COIN;
                lookString = '获取免广告币';
                break;
            }
            case userInterface_1.REWARD_TYPE.POWER: {
                lookOverFunction = function () {
                    gameEngine_1.services().userSrv.addPowerOfVideo();
                };
                rewardType = userInterface_1.REWARD_TYPE.POWER;
                lookString = '获取体力';
                break;
            }
            // case REWARD_TYPE.DIAMOND: {
            //     lookOverFunction = () => {
            //         console.warn('#841801 钻石未定义');
            //     }
            //     rewardType = REWARD_TYPE.DIAMOND;
            //     lookString = '获取钻石';
            //     break;
            // }
            default: {
                throw '#900224 未知定义道具';
            }
        }
        var videoFun = function () {
            cc.director.pause();
            gameEngine_1.services().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                lookOverFunction();
                //
                if (_this.m_propType == userInterface_1.REWARD_TYPE.COIN && gameEngine_1.default.getServices().userSrv.getExtraAd() != "1") {
                    // 打开额外的界面
                    MainRoot_1.default.UISystem.OpenPage(Enum_1.PAGE.EXTRA_AD_PAGE);
                }
                else {
                    gameEngine_1.modules().uiControlModule.showGetRewarded(rewardType, _this.m_propCount);
                }
                cc.director.resume();
            }, function () {
                cc.director.resume();
            }, function () {
                cc.director.resume();
            }, lookString);
        };
        //查看视频
        if (this.m_propType == userInterface_1.REWARD_TYPE.COIN) {
            videoFun();
        }
        else {
            if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
                gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
                lookOverFunction();
                gameEngine_1.modules().uiControlModule.showGetRewarded(rewardType, this.m_propCount);
            }
            else {
                videoFun();
            }
        }
    };
    addUserProp.prototype.OnLookInfinityBtn = function () {
        var _this = this;
        gameEngine_1.default.getManagers().soundMgr.playSound('mainSound/anNiu').then();
        var getFun = function () {
            var str = _this.infinityStr[addUserProp_1.lookedTimes];
            _this.showHintLb(str);
            addUserProp_1.lookedTimes++;
            _this.UpdateLookLabel();
            if (addUserProp_1.lookedTimes == gameConfig_1.default.INFINTY_VIDEO_TIME) {
                //进入无限体力模式
                gameEngine_1.default.getServices().userSrv.setPower(999, true, true);
                gameEngine_1.default.getServices().userSrv.setInfinity(1);
                gameEngine_1.default.getServices().userSrv.setInfinityTime();
                gameEngine_1.default.getModules().uiControlModule.showGetRewarded(userInterface_1.REWARD_TYPE.POWER, 999, '获得体力');
                _this.onClose();
            }
        };
        if (addUserProp_1.lookedTimes < gameConfig_1.default.INFINTY_VIDEO_TIME) {
            if (gameEngine_1.default.getServices().userSrv.getCoins() > 0) {
                gameEngine_1.default.getServices().userSrv.setCoins(-1, true);
                getFun();
            }
            else {
                gameEngine_1.default.getServices().miniGameSrv.getAppApiInstance().loadAndShowVideoAd(function () {
                    getFun();
                }, function () {
                }, null, '解锁无限体力');
            }
        }
    };
    addUserProp.prototype.showHintLb = function (str) {
        if (str != null) {
            var node_1 = cc.instantiate(this.hintNode);
            var hintLb = node_1.getChildByName("label").getComponent(cc.Label);
            hintLb.string = str;
            node_1.active = true;
            node_1.parent = this.hintNode.parent;
            cc.tween(node_1).by(2, { y: 100 }).call(function () {
                node_1.destroy();
            }).start();
        }
    };
    addUserProp.prototype.UpdateLookLabel = function () {
        if (this.lbInfinityNum) {
            this.lbInfinityNum.string = "(" + addUserProp_1.lookedTimes.toString() + "/" + gameConfig_1.default.INFINTY_VIDEO_TIME + ")";
        }
    };
    var addUserProp_1;
    addUserProp.lookedTimes = 0;
    __decorate([
        property(cc.Node)
    ], addUserProp.prototype, "detail", void 0);
    __decorate([
        property(cc.Label)
    ], addUserProp.prototype, "title", void 0);
    __decorate([
        property(cc.Label)
    ], addUserProp.prototype, "showNum", void 0);
    __decorate([
        property(cc.Sprite)
    ], addUserProp.prototype, "spIcon", void 0);
    __decorate([
        property([cc.SpriteFrame])
    ], addUserProp.prototype, "spfIcons", void 0);
    __decorate([
        property({ type: cc.Sprite, displayName: "标题图片" })
    ], addUserProp.prototype, "titleImg", void 0);
    __decorate([
        property({ type: cc.Sprite, displayName: "内容图片" })
    ], addUserProp.prototype, "messageImg", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "无限体力" })
    ], addUserProp.prototype, "infinityBtn", void 0);
    __decorate([
        property({ type: cc.Label, tooltip: "无限体力次数文本" })
    ], addUserProp.prototype, "lbInfinityNum", void 0);
    __decorate([
        property({ type: cc.Node, tooltip: "提示节点" })
    ], addUserProp.prototype, "hintNode", void 0);
    __decorate([
        property({ type: videoBtn_1.default })
    ], addUserProp.prototype, "videoBtn", void 0);
    addUserProp = addUserProp_1 = __decorate([
        ccclass
    ], addUserProp);
    return addUserProp;
}(cc.Component));
exports.default = addUserProp;

cc._RF.pop();